package org.saxion.aktiehuis.aop;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;



public class ShowException extends JDialog {
	

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JButton okButton;
	private JLabel lblError;
	
	
	public ShowException()
	{
		initialize();
	}
	

	/**
	 * Create the dialog.
	 */
	public void initialize() {
		setTitle("Error");
		setBounds(100, 100, 400, 250);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			lblError = new JLabel(" ERROR! ");
			contentPanel.add(lblError);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
				
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						System.exit(1);
					}
				});
			}
		}

	}
	
	public void addConfirmListener(ActionListener listener) {
		okButton.addActionListener(listener);
	}
	

	/*** This is the method which I would like to execute* if there is an exception raised.*/ 
	public void AfterThrowingAdvice(Exception ex)
	{ 
		System.err.println("There has been an exception: " + ex.toString()); 
		lblError.setText("There has been an exception: " + ex.toString());
		this.setVisible(true);
	}

}
